package com.imay.live.adapter.family;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.live.R;
import com.imay.live.manager.FamilyAccountManager;
import com.imay.live.model.FamilyModel;
import com.imay.live.utils.GlideUtil;

import java.util.List;

/**
 * Created by chan on 2017/4/6 0006.
 * 搜索
 */

public class SearchFamilyAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public final static int VIEWTYPE_LINEAR_CONTENT = 0x114;//推荐结果

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public SearchFamilyAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(VIEWTYPE_LINEAR_CONTENT, R.layout.searchfamily_item);
    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        if (item.getItemType() == VIEWTYPE_LINEAR_CONTENT) {
            FamilyModel model = (FamilyModel) item;
            TextView tv_nick = helper.getView(R.id.tv_nick);
            tv_nick.setText(model.getName());
            helper.setText(R.id.tv_meihao, model.getAnnouncement());
            helper.setText(R.id.tv_live_level, String.valueOf(model.getLv()));
            helper.setText(R.id.tv_family_nick, model.getDesignation());
            if (FamilyAccountManager.isMyFamily(model.getId())) {
                helper.setBackgroundRes(R.id.tv_family_nick, R.drawable.shape_corner2_ff90);
            } else {
                helper.setBackgroundRes(R.id.tv_family_nick, R.drawable.shape_corner2_ff0);
            }
            helper.setBackgroundRes(R.id.tv_live_level, R.mipmap.ico_jiazutubiao);
            ImageView imageView = helper.getView(R.id.iv_searchhead);
            GlideUtil.loadRectangleImage(imageView, model.getUrl(), R.dimen.radius_4x);
            helper.addOnClickListener(R.id.rl_left);
            helper.addOnClickListener(R.id.search_right);
        }
    }
}
